package lynch.display 
{
	import Elegant.display.Container;
	import Elegant.utils.ArrayUtil;
	import Elegant.utils.EnterFrameHandler;
	import Elegant.utils.VectorUtil;
	import flash.display3D.Context3D;
	import flash.display3D.Context3DCompareMode;
	import flash.display3D.Context3DStencilAction;
	import flash.display3D.Context3DTriangleFace;
	import flash.events.Event;
	import starling.core.RenderSupport;
	import starling.core.Starling;
	import starling.display.DisplayObject;
	/**
	 * invented z sort
	 * as usual, there's only one Depth2DContainer in scene of a game
	 * it will set the depthMask to true and passCompareMode to always(because in 2d, there's no z) in context3D.setDepthTest
	 * @author 小痛
	 */
	public class Depth2DContainer extends Container 
	{
		/**
		 * @param	context3D	easy to switch, and the static is slower
		 */
		public function Depth2DContainer(context3D:Context3D) 
		{
			super();
			EnterFrameHandler.add(inventedZ);
		}
		
		override protected function dispose():void 
		{
			EnterFrameHandler.remove(inventedZ);
			super.dispose();
		}
		
		/**
		 * sort children in every enterframe event
		 * @param	e
		 */
		private function inventedZ():void 
		{
			VectorUtil.quickSortProperties(Vector.<*>(mChildren), "y");
		}
	}
}